"""
Basic logging operations, mainly output to stdout/stderr
"""
import sys
import logging

DEBUG = logging.DEBUG
INFO = logging.INFO
WARNING = logging.WARNING
ERROR = logging.ERROR
CRITICAL = logging.CRITICAL

logging.basicConfig(level=CRITICAL)
logger = logging.getLogger('default')

def set_logging(level = WARNING):
    logger.setLevel(level)
    
def debug(msg, *args, **kwargs):
    logger.debug(msg, *args, **kwargs)
    
def warning(msg, *args, **kwargs):
    logger.warning(msg, *args, **kwargs)
    
def error(msg, *args, **kwargs):
    logger.error(msg, *args, **kwargs)
    
def get_file_logger(filename, level=INFO):
    """
    Create and return file logger.
    """
    formatter = logging.Formatter('%(levelname)-8s: %(message)s')
    handler = logging.FileHandler(filename, mode="w")
    handler.setFormatter(formatter)
    file_logger = logging.getLogger('report')
    file_logger.propagate = 0
    file_logger.addHandler(handler)
    file_logger.setLevel(level)
    
    print len(file_logger.handlers)
    return file_logger